
-- 对阵 界面 计分板
local GuildWarFightTipPlateRender = app.mvc.createRenderClass(...)
local CrossServerGuildWarHelper = require("app.crossServer.views.guildWar.CrossServerGuildWarHelper")
--data =
function GuildWarFightTipPlateRender.create(node)
    local sprite = GuildWarFightTipPlateRender.extend(node)
    sprite:init()
    return sprite
end

function GuildWarFightTipPlateRender:init(data)
    self.super.init(self, data)
    self._ui["Panel_1/btn_tips_1"]:addClickEventListener(handler(self, self._onClickTip))
    self._ui["Panel_1/btn_tips_2"]:addClickEventListener(handler(self, self._onClickTip))
    self:registerViewEvent({
        {name = ViewEvent.CSGuildWar_MyPowerRankInGuild, callback = handler(self, self._onGetMyRankInGuild)},
    })    
    self._ui.Panel_2:setTouchEnabled(true)
    self._ui.Panel_2:addClickEventListener(handler(self, self._onClickLifePanel))
end

function GuildWarFightTipPlateRender:_onClickLifePanel(sender)
    local colorNormal = cc.c3b(255, 225, 132)
    local contents = {}
    local part1 = {}
    table.insert(part1, {text = L("WGWLifeTips"), color = colorNormal})
    table.insert(contents, part1)

    local touchPos = sender:getTouchEndPosition()
    local p = sender:convertToWorldSpace(cc.p(0,0))
    local height = sender:getContentSize().height

    local param = {tipsType = Enums.TipsType.contents,contents = contents, closeCallBack = function() app:dispatchCustomEvent("EVENT_CLOSE_FLOAT") end}
    UIHandler:setLastTouchPosition(p.x , p.y + height/2 + 20)
    app:dispatchCustomEvent("EVENT_OPEN_FLOAT", {params=param})
end

function GuildWarFightTipPlateRender:_onClickTip()
    app:sendMsg("CrossServerController", "showJoinTips")
end

function GuildWarFightTipPlateRender:_onGetMyRankInGuild(eventName, rank, memberNum)
    self:refresh()
end

function GuildWarFightTipPlateRender:refresh()
    local csGuildWarData = UD.csGuildWarData
    local stage = csGuildWarData:getTodayStage()
    if stage == Enums.CSGuildWarTodayStage.Fighting or  stage == Enums.CSGuildWarTodayStage.End or stage == Enums.CSGuildWarTodayStage.GetTicketEnd then
        self._ui.Panel_1:setVisible(false)
        self._ui.Panel_2:setVisible(true)
        local matchInfo = csGuildWarData:getCurMatchInfo()
        if matchInfo then
            local guild1, guild2 = matchInfo:getGuildWithSort()
            if stage == Enums.CSGuildWarTodayStage.End then
                if guild1:getGuildId() == matchInfo:getWinner() then
                    self._ui["Panel_2/tlt"]:setString(L("ui_csd_675"))
                else
                    self._ui["Panel_2/tlt"]:setString(L("ui_csd_811"))
                end
            else
                self._ui["Panel_2/tlt"]:setString(L("CSGuildWarLeftLife"))
            end
            
            self._ui["Panel_2/num_1"]:setString(guild1:getMemberLifeNum())
            if guild2 then
                self._ui["Panel_2/num_2"]:setString(guild2:getMemberLifeNum())
            else
                self._ui["Panel_2/num_2"]:setString(0)
            end
        end
    else
        self._ui.Panel_1:setVisible(true)
        self._ui.Panel_2:setVisible(false)
        local hour, min = CrossServerGuildWarHelper.getGuildWarStartTime()
        self._ui["Panel_1/time"]:setString(hour..":"..min)

        -- if stage == Enums.CSGuildWarTodayStage.GetTicketEnd then
        --     local ticketState = csGuildWarData:getTicketState()
        --     if ticketState == Enums.CSGuildWarTicketState.Yes then
        --         self._ui["Panel_1/btn_tips_1"]:setVisible(false)
        --         self._ui["Panel_1/btn_tips_2"]:setVisible(true)
        --     else
        --         self._ui["Panel_1/btn_tips_1"]:setVisible(true)
        --         self._ui["Panel_1/btn_tips_2"]:setVisible(false)
        --     end
        -- else
            local curGuildPowerRank = csGuildWarData:getMyInGuildPowerRank()
            if curGuildPowerRank then
                if CrossServerGuildWarHelper.isSafeGetTicket(curGuildPowerRank) then
                    self._ui["Panel_1/btn_tips_1"]:setVisible(false)
                    self._ui["Panel_1/btn_tips_2"]:setVisible(true)
                else
                    self._ui["Panel_1/btn_tips_1"]:setVisible(true)
                    self._ui["Panel_1/btn_tips_2"]:setVisible(false)
                end
            else
                self._ui["Panel_1/btn_tips_1"]:setVisible(false)
                self._ui["Panel_1/btn_tips_2"]:setVisible(true)
            end
        -- end
    end
end




return GuildWarFightTipPlateRender